//
//  HomeCanTestTableViewCell.m
//  ZJControlsClass
//
//  Created by mac on 2024/11/15.
//

#import "HomeCanTestTableViewCell.h"
#import "HomeAvailableNetworking.h"
#import "SaTime.h"

@interface HomeCanTestTableViewCell ()


@property (nonatomic,strong) UIView * follewView;
@property (nonatomic,strong) UILabel * titleLabel;
@property (nonatomic,strong) UILabel * typeLabel;
@property (nonatomic,strong) UILabel * addLabel;
@property (nonatomic,strong) UILabel * timeLabel;
@property (nonatomic,strong) UILabel * durationLabel;
@property (nonatomic,strong) UILabel * numberLabel;
@property (nonatomic,strong) UIView * v;
@property (nonatomic,strong) UIButton * testBtn;

@property (nonatomic,strong) HomeCreatTestNetworking * manager;

@end



@implementation HomeCanTestTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        
        self.contentView.backgroundColor = COLOR_RGB(241, 241, 241);
        [self configUI];
        
    }
    
    return self;
    
}

-(void)setModel:(HomeAvailableModel *)model{
    _model = model;
    self.titleLabel.text = model.subject;
    self.typeLabel.text = model.subject;
    self.addLabel.text = [NSString stringWithFormat:@"考试地点：%@",model.location];
    self.timeLabel.text = [NSString stringWithFormat:@"考试时间：%@",model.startTime];
    self.durationLabel.text = [NSString stringWithFormat:@"考试时长：%@",[SaTime transFormTime:model.startTime endStr:model.endTime]];
    self.numberLabel.text = [NSString stringWithFormat:@"考试可预约人数：%@",model.maxCapacity];
    
}




-(void)configUI{
    [self.contentView addSubview:self.follewView];
    [self.follewView addSubview:self.titleLabel];
    [self.follewView addSubview:self.typeLabel];
    [self.follewView addSubview:self.addLabel];
    [self.follewView addSubview:self.timeLabel];
    [self.follewView addSubview:self.durationLabel];
    [self.follewView addSubview:self.numberLabel];
    [self.follewView addSubview:self.v];
    [self.follewView addSubview:self.testBtn];
    
    [self.follewView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).with.offset(ALIGN_WIDTH_PT(12));
        make.top.equalTo(self.contentView).with.offset(ALIGN_HEIGHT_PT(10));
        make.right.equalTo(self.contentView).with.offset(-ALIGN_WIDTH_PT(12));
        make.bottom.equalTo(self.contentView);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.follewView).with.offset(ALIGN_WIDTH_PT(10));
        make.top.equalTo(self.follewView).with.offset(ALIGN_HEIGHT_PT(12));
        make.right.equalTo(self.follewView).with.offset(-ALIGN_WIDTH_PT(10));
    }];
    
    [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_left);
        make.top.equalTo(self.titleLabel.mas_bottom).with.offset(ALIGN_HEIGHT_PT(10));
    }];
    
    [self.addLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_left);
        make.top.equalTo(self.typeLabel.mas_bottom).with.offset(ALIGN_HEIGHT_PT(15));
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_left);
        make.top.equalTo(self.addLabel.mas_bottom).with.offset(ALIGN_HEIGHT_PT(10));
    }];
    
    [self.durationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_left);
        make.top.equalTo(self.timeLabel.mas_bottom).with.offset(ALIGN_HEIGHT_PT(10));
    }];
    
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_left);
        make.top.equalTo(self.durationLabel.mas_bottom).with.offset(ALIGN_HEIGHT_PT(10));
    }];
    
    [self.v mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_left);
        make.top.equalTo(self.numberLabel.mas_bottom).with.offset(ALIGN_HEIGHT_PT(15));
        make.right.equalTo(self.follewView).with.offset(-ALIGN_WIDTH_PT(12));
        make.height.equalTo(@(1));
    }];
    
    
    [self.testBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.follewView).with.offset(-ALIGN_WIDTH_PT(12));
        make.top.equalTo(self.v.mas_bottom).with.offset(ALIGN_HEIGHT_PT(12));
        make.size.equalTo(@(CGSizeMake(ALIGN_WIDTH_PT(80), ALIGN_HEIGHT_PT(30))));
    }];
    
    
    
    
    
}



-(void)respondsTo_testBtn{
    
    [LUtilityTools showAlertWithTitle:@"温馨提示" message:[NSString stringWithFormat:@"是否确认预约%@",self.model.subject] cancelTitle:@"不了" buttonAction:^{
        
    } sureTitle:@"确认预约" ButtonAction:^{
        
        NSDictionary * paramer = @{@"examId":self.model.id};
        [self.manager dispatchTaskWithParam:paramer completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
            if (responseObject && [responseObject[@"code"] intValue] ==  200){
                [MBProgressHUD showSuccess:@"预约成功"];
                if (self.delegate && [self.delegate respondsToSelector:@selector(reloadTableView)]){
                    [self.delegate reloadTableView];
                }
                
            }else{
                [LUtilityTools showAlertWithTitle:@"温馨提示" message:responseObject[@"msg"] buttonAction:^{
                    
                }];
            }
        }];
        
        
    }];
    
    
}




#pragma mark -- 懒加载
-(UIView *)follewView{
    if (!_follewView){
        _follewView = [UIView new];
        _follewView.backgroundColor = [UIColor whiteColor];
        _follewView.layer.cornerRadius = 10;
        _follewView.layer.masksToBounds = YES;
    }
    return _follewView;
}

-(UILabel *)titleLabel{
    if (!_titleLabel){
        _titleLabel = [UILabel new];
        _titleLabel.text = @"长期人员安全考试";
        _titleLabel.textColor = [UIColor blackColor];
        _titleLabel.font = [UIFont systemFontOfSize:16 weight:0.5];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _titleLabel;
}

-(UILabel *)typeLabel{
    if (!_typeLabel){
        _typeLabel = [UILabel new];
        _typeLabel.text = @"申办长期人员通行证";
        _typeLabel.textColor = [UIColor blackColor];
        _typeLabel.font = FONT14;
        _typeLabel.textAlignment = NSTextAlignmentLeft;
        _typeLabel.backgroundColor = COLOR_RGB(244, 244, 244);
    }
    return _typeLabel;
}

-(UILabel *)addLabel{
    if (!_addLabel){
        _addLabel = [UILabel new];
        _addLabel.text = @"考试地点：机场楼13楼01号";
        _addLabel.textColor = [UIColor blackColor];
        _addLabel.textAlignment = NSTextAlignmentLeft;
        _addLabel.font = FONT14;
    }
    return _addLabel;
}

-(UILabel *)timeLabel{
    if (!_timeLabel){
        _timeLabel = [UILabel new];
        _timeLabel.text = @"考试时间：2024.11.05 10:30";
        _timeLabel.textColor = [UIColor blackColor];
        _timeLabel.textAlignment = NSTextAlignmentLeft;
        _timeLabel.font = FONT14;
    }
    return _timeLabel;
}
-(UILabel *)durationLabel{
    if (!_durationLabel){
        _durationLabel = [UILabel new];
        _durationLabel.text = @"考试时长：60分钟";
        _durationLabel.textColor = [UIColor blackColor];
        _durationLabel.textAlignment = NSTextAlignmentLeft;
        _durationLabel.font = FONT14;
    }
    return _durationLabel;
}
-(UILabel *)numberLabel{
    if (!_numberLabel){
        _numberLabel = [UILabel new];
        _numberLabel.text = @"剩余可预约人数：40人";
        _numberLabel.textColor = [UIColor blackColor];
        _numberLabel.textAlignment = NSTextAlignmentLeft;
        _numberLabel.font = FONT14;
    }
    return _numberLabel;
}

-(UIView *)v{
    if (!_v){
        _v = [UIView new];
        _v.backgroundColor = COLOR_RGB(228, 228, 228);
    }
    return _v;
}

-(UIButton *)testBtn{
    if (!_testBtn){
        _testBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_testBtn setTitle:@"预约考试" forState:(UIControlStateNormal)];
        [_testBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        _testBtn.titleLabel.font = FONT14;
        _testBtn.backgroundColor = COLOR_RGB(50, 113, 237);
        _testBtn.layer.cornerRadius = 5;
        _testBtn.layer.masksToBounds = YES;
        [_testBtn addTarget:self action:@selector(respondsTo_testBtn) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _testBtn;
}

-(HomeCreatTestNetworking *)manager{
    if (!_manager){
        _manager = [HomeCreatTestNetworking new];
    }
    return _manager;
}


@end
